package org.ypx.center.controller.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ypx.center.service.IUserService;
import org.ypx.db.entity.User;
import org.ypx.shared.common.Result;
import org.ypx.web.App;

import javax.servlet.http.HttpSession;

/**
 * @author Yan Peixuan
 * @date 2017/3/28 21:06
 * @description
 */
@Controller
@RequestMapping(value = "admin")
public class adminControllerImpl {
    @Autowired
    private IUserService userService;

    @RequestMapping(value = "login")
    @ResponseBody
    public Result login(User user, HttpSession session) {
        //User user = null;
        Result<User> result = userService.loadUserByUsernameAndPassword(user);
        if (result != null) {
            // logger.info("登陆成功：{}", result);
            session.setAttribute(App.USER_SESSION_KEY, result.getData());
            System.out.println("result.getData() = " + result.getData());
            return result;
        } else {
            return result;
        }
    }


}
